/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.power.visual;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;


public class LabelTest {

  private JLabel label;


  public LabelTest()
  {
    label = new JLabel();
    label.setSize(150, 25);
    label.setLocation(10, 10);
    label.setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY));
  }

  public JLabel getLabel()
  {
    return label;
  }

  public void showMessages()
  {
    Thread th = new Thread(new Runnable() {
      @Override
      public void run()
      {
        for(int i = 0; i <= 10; i++) {
          label.setText("Message" + i);
          label.repaint();
          try
          {
            Thread.sleep(100);
          } catch (InterruptedException ex) { 
            ex.printStackTrace();
          }
        }
      }
    });
    th.start();
  }

  public static void main(String[] args)
  {
    JFrame f = new JFrame("LabelTest");
    f.setLayout(null);
    f.setSize(200, 120);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setLocation(300, 300);

    final LabelTest test = new LabelTest();
    
    JButton button = new JButton("Start");
    button.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e)
      {
        test.showMessages();
      }
    });
    button.setBounds(10, 45, 80, 30);

    f.add(test.getLabel());
    f.add(button);

    f.setVisible(true);
  }

}
